package com.lemon.tuvi2015;

import java.util.ArrayList;

import org.json.JSONException;

import com.lemon.tuvi2015.adapter.XongdatAdapter;
import com.lemon.tuvi2015.object.XongdatObject;
import com.lemon.tuvi2015.util.JsonParser;
import com.lemon.tuvi2015.util.TagName;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

public class XongdatListFragment extends Fragment {
	String content = "";
	String key = "";
	ArrayList<XongdatObject> arrayList;
	ListView listView;
//
//	public XongdatListFragment newInstance(String result, String key) {
//		XongdatListFragment fragment = new XongdatListFragment();
//		Bundle args = new Bundle();
//		args.putString(TagName.TITLE, result);
//		args.putString(TagName.KEY, key);
//		Log.d("", result);
//		Log.d("", key);
//		return fragment;
//	}
//	public XongdatListFragment() {
//		// TODO Auto-generated constructor stub
//	}
	
	public XongdatListFragment(String result, String key) {
		content=result;
		this.key=key;
	}
	
//	@Override
//	public void onCreate(Bundle savedInstanceState) {
//		super.onCreate(savedInstanceState);
//		if (getArguments() != null) {
//			content = getArguments().getString(TagName.TITLE);
//			key = getArguments().getString(TagName.KEY);
//			Log.i("", "content:"+content);
//			Log.i("", "key:"+key);
//		}
//	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View android = inflater.inflate(R.layout.listview, container, false);
		findviewByID(android);
		try {
			Log.i("", content);
			Log.i("", key);
			arrayList = JsonParser.readxongdat(content, key);

			if (arrayList != null && arrayList.size() > 0) {
				listView.setAdapter(new XongdatAdapter(getActivity(), arrayList));
			} else
				Log.e("", "nullllllllllllllllllllllllllllllllllllllllllll");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return android;
	}

	void findviewByID(View view) {
		listView = (ListView) view.findViewById(R.id.listView);
	}

}
